package com.example.administrator.basedemos.okhttp;


import com.example.administrator.basedemos.utils.LogUtil;
import com.google.gson.internal.$Gson$Types;

import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import okhttp3.Call;

/**
 * 创建者     ZCL
 * 创建时间   2018/3/14 18:14
 * 描述	      ${关于异步请求基础判断}
 * <p>
 * 更新者     $Author$
 * 更新时间   $Date$
 * 更新描述   ${TODO}
 */

public abstract class BaseCallBack<T> {
    private static final String TAG = "BaseCallBack";


    public BaseCallBack() {
        mType = getSuperclassTypeParameter(this.getClass());
    }

    //獲取泛型 mType
    static Type getSuperclassTypeParameter(Class<?> subclass) {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class) {
            // throw new RuntimeException("Missing type paramter!");
            return null;
        }
        ParameterizedType parameterizedType = (ParameterizedType) superclass;
        return $Gson$Types.canonicalize(parameterizedType.getActualTypeArguments()[0]);
    }

    public Type mType;

    public abstract void onSuccess(T t);

    public  void onError(int code){
        LogUtil.util(TAG,"baseCallback  error!-----------:"+code);
    }

    public  void onFaile(Call call, IOException e){
        e.getLocalizedMessage();
        LogUtil.util(TAG,"baseCallback  Fail!-------------:"+e.getLocalizedMessage());
    }
}
